#include <iostream>
#include <string>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        int ans = 0;
        int tmp = 0;
        for (int i=0; i<s.size(); ++i){
            if(s[i]=='O') ans += ++tmp;
            else tmp = 0;
        }
        cout << ans << endl;
    }

    return 0;
}
